package controllers

import actors.{MissionManager, UpdateMissionActor}
import akka.actor.ActorSystem
import akka.actor.typed.PostStop
import akka.actor.typed.scaladsl.Behaviors
import command.{CommandUtils, MissionUtils}
import dao._
import implicits.BlastTool
import implicits.Implicits._
import models.Tables._
import org.joda.time.DateTime
import org.zeroturnaround.zip.ZipUtil
import play.api.libs.json.{JsValue, Json}
import play.api.mvc.{AbstractController, ControllerComponents, WebSocket}
import tool.{FormTool, Tool, TypedActorFlow}
import utils.Utils

import java.io.File
import javax.inject.Inject
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

/**
 * Created by yz on 16/9/2021
 */
class ToolController @Inject()(cc: ControllerComponents)(
  implicit val userDao: UserDao,
  implicit val sampleDao: SampleDao,
  implicit val modeDao: ModeDao,
  implicit val missionDao: MissionDao,
  implicit val system: ActorSystem,
) extends AbstractController(cc) with BlastTool {

  def downloadExampleData = Action {
    implicit request =>
      val data = FormTool.fileNameForm.bindFromRequest().get
      val resultFile = new File(Tool.exampleDir, data.fileName)
      Ok.sendFile(resultFile).withHeaders(
        CONTENT_DISPOSITION -> s"attachment; filename=${
          resultFile.getName
        }",
        CONTENT_TYPE -> "application/x-download"
      )
  }


}
